package com.chenyuxin.ilp.controller.file;

import com.chenyuxin.ilp.model.pojo.Result;
import com.chenyuxin.ilp.service.file.OpenFileService;
import com.chenyuxin.ilp.util.SecurityUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/file/open")
public class OpenFileController {
    @Autowired
    private OpenFileService openFileService;
    @GetMapping("/all/{hostuserid}")
    public Result selectAllOpenFile(@PathVariable("hostuserid") String hostUserId){
        String userId = SecurityUtil.getUserId();
        return openFileService.selectAllOpenFile(userId,hostUserId);
    }
    @GetMapping("/select")
    public Result selectSon(@RequestParam("parentid")Long parentId,@RequestParam("hostuserid") String hostUserId){
        String userId = SecurityUtil.getUserId();
        return openFileService.selectByParentId(parentId,hostUserId,userId);
    }
    @GetMapping("/preview")
    public Result previewOpenFile(@RequestParam("fileid")Long fileid
            ,@RequestParam("hostuserid")String hostUserId){
        String userId = SecurityUtil.getUserId();
        return openFileService.previewOpenFile(fileid,hostUserId,userId);
    }
    @GetMapping("/download")
    public ResponseEntity<byte[]> downloadOpenFile(@RequestParam("fileid")Long fileId,
                                                   @RequestParam("hostuserid")String hostUserId) {
        String userId = SecurityUtil.getUserId();
        return openFileService.downLoadFile(fileId,hostUserId,userId);
    }
}
